package com.tarena.lbs.activity.dao.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tarena.lbs.activity.dao.mapper.ActivityMapper;
import com.tarena.lbs.activity.dao.repository.ActivityRepository;
import com.tarena.lbs.activity.pojo.po.ActivityPO;
import com.tarena.lbs.activity.pojo.query.ActivityQuery;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

@Repository
public class ActivityRepositoryImpl implements ActivityRepository {

    @Resource
    private ActivityMapper activityMapper;

    public List<ActivityPO> selectAll(ActivityQuery query) {
        LambdaQueryWrapper<ActivityPO> queryWrapper = new LambdaQueryWrapper<>();
        String name = query.getActivityName();
        Integer type = query.getType();
        Integer deliveryChannel = query.getDeliveryChannel();
        Integer status = query.getStatus();
        queryWrapper.eq(name != null, ActivityPO::getActivityName, name);
        queryWrapper.eq(type != null, ActivityPO::getActivityType, type);
        queryWrapper.eq(deliveryChannel != null, ActivityPO::getDeliveryChannel, deliveryChannel);
        queryWrapper.eq(status != null, ActivityPO::getStatus, status);
        return activityMapper.selectList(queryWrapper);
    }

    public Long selectCount(ActivityQuery query) {
        return activityMapper.selectCount(null);
    }
}
